﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BLL;
using GameGo.Models;
using Model;

namespace GameGo.Controllers
{
    public class HomeController : Controller
    {
        usersBLL userContext = new usersBLL();
        goodsBLL goodsContext = new goodsBLL();
        public ActionResult Index()
        {
            IndexViewModel sets = new IndexViewModel()
            {
                guns = goodsContext.GetGoodsByType(3, 10),
                randoms = goodsContext.GetGoodsByRandom(10),
                knife = goodsContext.GetGoodsByType(1, 10),
                stamp = goodsContext.GetGoodsByType(8, 10),
                others = goodsContext.GetGoodsByType(9, 10)

            };
            return View(sets);
        }
        public ActionResult LoginForm(users user)
        {
            return View();
        }
        [HttpPost]
        public string Login(users user)
        {
            string data = null;
            users newuser = user;
            users target = userContext.LoginValid(user);
            if (target == null)
                return "false";
            else
            {
                Session["UserID"] = target.ID;
                Session["UserName"] = target.userName;
                Session["UserImage"] = target.userImage;
                Session["NickName"] = target.nickName;
                data = "true";
            }
            return data;
        }
        public void Logout()
        {
            Session["UserID"] = null;
            Session["UserName"] = null;
            Session["UserImage"] = null;
            Session["NickName"] = null;
        }
        
    }
}